import * as THREE from "three";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
class Web3D {
    constructor() {

    }
    createCamera(width, height) {
        // 初始化相机
        var camera = new THREE.PerspectiveCamera(
            50,
            width / height,
            0.01,
            10000
        );

        camera.position.set(47, 15, 29);
        camera.rotation.set(-Math.PI / 7, Math.PI / 4, Math.PI / 10);
        camera.lookAt(0, 0, 0);

        return camera;
    }

    createWebGLRenderer(width, height) {
        var renderer = new THREE.WebGLRenderer({
            antialias: true,
            alpha: true,
            logarithmicDepthBuffer: true,
        });
    
            return renderer;
    }

    loadModel(modelName,scene) {
        const loader = new GLTFLoader();
        loader.setPath("/model/");
  
        var mats = new THREE.MeshBasicMaterial({
          color: 0xababab,
          transparent: false,
          opacity: 0.9,
        });
        var matGlow = new THREE.MeshStandardMaterial({
          color: 0xffffff,
          metalness: 1,
          roughness: 0,
          transparent: true,
          opacity: 0.6,
        });
        loader.load(modelName, (gltf) => {
          if (modelName == "mark.glb") {
            this.mark = gltf.scene;
            // 对模型进行放大
            this.mark.scale.set(20, 20, 20); // 按照需要的倍数进行放大
            this.mark.rotation.y = 0;
            this.mark.position.set(0, 0, 0);
            this.scene.add(this.mark);
          } else {
            gltf.scene.traverse(function (child) {
              if (child.isMesh) {
                if (
                  child.name.includes("wall") ||
                  child.name.includes("stair") ||
                  child.name.includes("screen") ||
                  child.name.includes("desk") ||
                  child.name.includes("pillar") ||
                  child.name.includes("slope") ||
                  child.name.includes("chair")
                ) {
                  console.log(child.name);
                  // child.material = matGlow;
  
                  const edges = new THREE.EdgesGeometry(child.geometry);
                  const lineMaterial = new THREE.LineBasicMaterial({
                    color: 0xfffffff,
                    linewidth: 1,
                  });
                  const edgesMesh = new THREE.LineSegments(edges, lineMaterial);
                  scene.add(edgesMesh);
                }
              }
            });
  
            // 对模型进行放大
            scene.add(gltf.scene);
          }
        });
      }
}

export { Web3D }